home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-03-04 | 5.0 KB | 216 lines | [TEXT/ToyS] |
- property kasMinSpeed : 2
- property kasMaxSpeed : 20
- property kasErase : true
- property kasName : "Bounce V1.1"
-
- global gasWinLoc -- Location of window
-
- on run
- pfLoad()
- idle
- end run
-
-
- on idle
- set dims to random number from 250 to 500
- set ballDim to random number from 25 to 125
-
- set drawWin to ¬
- display drawing titled ("Bounce 1.1 - shift=quit, w/opt to toggle trace") ¬
- located at gasWinLoc ¬
- with dimensions {dims, dims}
-
- set gasWinLoc to screen location of drawWin -- Save for comparison
-
- draw a box into drawWin ¬
- inside of {0, 0, dims, dims} ¬
- filling it by erasing it ¬
- using state {bg col64:{0, 0, 0}}
-
- set rgn to CreateRgn(ballDim)
- set ball to CreateBall(ballDim, rgn)
-
- set bbox to {0, 0, ballDim, ballDim}
- set sY to random number from kasMinSpeed to kasMaxSpeed
- set sX to random number from kasMinSpeed to kasMaxSpeed
-
- set userState to input state
-
- set i to 0
- set erase to kasErase
-
- repeat until (shift key down of userState) or (i > 9999)
- set item 1 of bbox to (item 1 of bbox) + sX
- set item 3 of bbox to (item 3 of bbox) + sX
- set item 2 of bbox to (item 2 of bbox) + sY
- set item 4 of bbox to (item 4 of bbox) + sY
-
- -- Hit bottom?
- if (item 4 of bbox ≥ dims) then
- set sY to -2 * (random number from kasMinSpeed to kasMaxSpeed)
- set item 2 of bbox to dims - ballDim
- set item 4 of bbox to dims
- end if
-
- -- Hit right?
- if (item 3 of bbox ≥ dims) then
- set sX to -(random number from kasMinSpeed to kasMaxSpeed)
- set item 1 of bbox to dims - ballDim
- set item 3 of bbox to dims
- end if
-
- -- Hit top?
- if (item 2 of bbox < 0) then
- set sY to round ((random number from kasMinSpeed to kasMaxSpeed) / 2)
- set item 2 of bbox to 0
- set item 4 of bbox to ballDim
- end if
-
- -- Hit left?
- if (item 1 of bbox < 0) then
- set sX to (random number from kasMinSpeed to kasMaxSpeed)
- set item 1 of bbox to 0
- set item 3 of bbox to ballDim
- end if
-
- draw a picture into drawWin ¬
- using data ball ¬
- inside of bbox ¬
- without recording
-
- if (erase) then
- set ballRgn to calculate region from the mapping ¬
- of region rgn inside of bbox
- set diffRgn to calculate region from the difference ¬
- of region rgn with region ballRgn
-
- draw a region into drawWin ¬
- using data diffRgn ¬
- filling it by erasing it ¬
- without recording
-
- set rgn to ballRgn
- end if
-
- set userState to input state
- set i to i + 1
- set sY to sY + 1 -- Gravity
- end repeat
-
- set winLoc to screen location of ¬
- (display drawing drawWin with disposal)
-
- if (winLoc is not gasWinLoc) then
- set gasWinLoc to winLoc
- pfSave()
- end if
-
- if (option key down of userState) then
- set kasErase to not kasErase
- return 1
- end if
-
- return 60
- end idle
-
-
- on CreateBall(dim, rgn)
- set ballWin to display drawing titled ¬
- "Creating Ball" with dimensions {dim, dim}
-
- set fgc to {} & ¬
- {random number from 444 to 44444} & ¬
- {random number from 444 to 44444} & ¬
- {random number from 444 to 44444}
- set box to {0, 0, dim, dim}
-
- set cnt to round (dim / 3)
-
- set colStepR to round ((65000 - (item 1 of fgc)) / cnt)
- set colStepG to round ((65000 - (item 2 of fgc)) / cnt)
- set colStepB to round ((65000 - (item 3 of fgc)) / cnt)
-
- repeat with i from 1 to cnt
- draw an oval into ballWin ¬
- inside of box ¬
- using state {fg col64:fgc, pen size:{2, 2}}
-
- set item 3 of box to (item 3 of box) - 1
- set item 4 of box to (item 4 of box) - 1
-
- draw an oval into ballWin ¬
- inside of box ¬
- using state {fg col64:fgc, pen size:{1, 1}}
-
- set item 1 of box to (item 1 of box) + 1
- set item 2 of box to (item 2 of box) + 1
- set item 3 of box to (item 3 of box) - 1
- set item 4 of box to (item 4 of box) - 1
-
- set item 1 of fgc to (item 1 of fgc) + colStepR
- set item 2 of fgc to (item 2 of fgc) + colStepG
- set item 3 of fgc to (item 3 of fgc) + colStepB
- end repeat
-
- set ball to ¬
- capture picture from ballWin ¬
- inside region rgn ¬
- using depth DepthOfMonitorContaining(screen location of ballWin) ¬
- with pixel conversion and dithering
-
- display drawing ballWin with disposal
-
- return ball
- end CreateBall
-
-
- on DepthOfMonitorContaining(pt)
- set displays to the display information
- repeat with dsp in displays
- if PtInRect(pt, monitor box of dsp) then ¬
- return monitor depth of dsp
- end repeat
- return monitor depth of item 1 of displays
- end DepthOfMonitorContaining
-
-
- on PtInRect(pt, rc)
- return (item 1 of pt ≥ item 1 of rc) ¬
- and (item 2 of pt ≥ item 2 of rc) ¬
- and (item 1 of pt ≤ item 3 of rc) ¬
- and (item 2 of pt ≤ item 4 of rc)
- end PtInRect
-
-
- on CreateRgn(dim)
- set ballWin to display drawing titled ¬
- "Creating Region" with dimensions {dim, dim}
-
- set box to {0, 0, dim, dim}
-
- draw an oval into ballWin ¬
- inside of box
-
- set rgn to capture region from ballWin
-
- display drawing ballWin with disposal
-
- return rgn
- end CreateRgn
-
-
- on pfLoad()
- try
- set myPref to load preference named kasName
- on error
- set myPref to {{-1, -1}}
- end try
-
- set gasWinLoc to item 1 of myPref
- end pfLoad
-
-
- on pfSave()
- save preference {gasWinLoc} named kasName
- end pfSave
-